package com.es.www.shallowCopy;

/**
 * @Created by michangtao
 * @Date 2022/5/12 14:44
 * @Description
 */
public class Operate {
    public static void main(String[] args) {
        Sheep sheep = new Sheep("肖恩", 2);
        sheep.setFriend(new Sheep("杰克", 3));
        System.out.println("羊：" + sheep.toString());
        Sheep clone1 = (Sheep) sheep.clone();
        System.out.println("克隆羊：" + clone1.toString());
        System.out.println(sheep == clone1);//false。原型模式，两个对象
        System.out.println(sheep.getFriend() == clone1.getFriend());//true。这就是浅拷贝，传递的是引用地址，此处的friend指向同一个对象地址。也就是说clone方法不会创建新的成员属性
        System.out.println(sheep.getFriend().hashCode());
        System.out.println(clone1.getFriend().hashCode());
    }
}
